import java.util.*;

public class Account {
    public final String name;
    public final int id;
    public double balance = 0;
    public static double interestRate = 0;
    private Date dateCreated;
    private ArrayList<Transaction> transactions;

    public static void main(String[] args) {
        interestRate = 0.015;
        Account george = new Account("George", 1122, 1000);
        george.deposit(30, null);
        george.deposit(40, null);
        george.deposit(50, null);
        george.withdraw(5, null);
        george.withdraw(4, null);
        george.withdraw(3, null);
        george.printAccountList();
    }

    public Account() {
        name = null;
        id = 0;
        dateCreated = new Date();
        transactions = null;
    }

    public Account(String name, int id, double balance) {
        this.name = name;
        this.id = id;
        this.balance = round(balance);
        dateCreated = new Date();
        transactions = new ArrayList<>();
    }

    public double getMonthlyInterestRate() {
        return interestRate / 12;
    }

    //从账户取出特定数额的存款，返回余额
    public double withdraw(double amount, String description) {
        amount = round(amount);
        if (amount > balance) return balance;
        balance -= amount;
        transactions.add(new Transaction(0, amount, balance, description));
        return balance;
    }

    //存入特定数额，返回余额
    public double deposit(double amount, String description) {
        amount = round(amount);
        balance += amount;
        transactions.add(new Transaction(1, amount, balance, description));
        return balance;
    }

    public ArrayList<Transaction> getTransactions() {
        return new ArrayList<>(transactions);
    }

    public void printTransactions() {
        for (Transaction t : transactions) t.print();
    }

    public void printAccountList() {
        System.out.println("Name: " + name + "    " + "Rate: " + interestRate +
                "    Balance: " + balance);
        System.out.println("Transactions: ");
        printTransactions();
    }

    public int getCreatedYear() {
        return dateCreated.getYear() + 1900;
    }

    public int getCreatedMonth() {
        return dateCreated.getMonth() + 1;
    }

    public int getCreatedDay() {
        return dateCreated.getDate();
    }

    public int getCreatedHour() {
        return dateCreated.getHours();
    }

    public int getCreatedMin() {
        return dateCreated.getMinutes();
    }

    public int getCreatedSec() {
        return dateCreated.getSeconds();
    }

    //保留两位小数
    public static double round(double d) {
        return Math.round(d * 100) * 1.0 / 100;
    }
}

class Transaction {
    private Date date;
    public final int type; //0表示取款，1表示存款
    public final double amount;
    public final double balance;
    public String description;

    public Transaction(int type, double amount, double balance, String description) {
        date = new Date();
        this.type = type;
        this.amount = Account.round(amount);
        this.balance = Account.round(balance);
        this.description = description;
    }

    public int getYear() {
        return date.getYear() + 1900;
    }

    public int getMonth() {
        return date.getMonth() + 1;
    }

    public int getDay() {
        return date.getDate();
    }

    public int getHour() {
        return date.getHours();
    }

    public int getMin() {
        return date.getMinutes();
    }

    public int getSec() {
        return date.getSeconds();
    }

    public void printTime() {
        System.out.print((date.getYear() + 1900) + "/" + (date.getMonth() + 1) + "/" +
                date.getDate() + " " + date.getHours() + ":" + date.getMinutes()
                + ":" + date.getSeconds());
    }

    public void print() {
        printTime();
        System.out.println();
        System.out.println("Type: " + (type == 0 ? "Withdraw" : "Deposit") + " "
                + "Amount: " + amount + " " + "Balance: " + balance);
        System.out.println("Description: " + description);
    }
}